
// import * as  signalR from '@microsoft/signalr';
// import url_config from '../../common/config'
// import { connect } from 'net';
// const baseUrl = process.env.NODE_ENV === 'development' ? url_config.baseUrl.dev : url_config.baseUrl.pro

import  * as signalR from "@microsoft/signalr"
// import urlConfig from './config.js'
export default {
    state: {
        connection: null,
    },
    mutations: {
        setConnection(state, connection) {
            state.connection = connection;
        },
        sethasConnected(state, hasConnected) {
            state.hasConnected = hasConnected;
        } 
    },
    getters: {},
    actions: {
        connect({ state, commit }) {
            return new Promise(async (resolve, reject) => {
                try {
                    let connection = new signalR.HubConnectionBuilder()
                        .withUrl(`http://192.168.199.178:8020/messagebus`)
						// http://localhost:8630//messagebus
                        .build();//构建连接
                    await connection.start();//启动连接
                    console.log("signalR is connected!");
                    commit('setConnection', connection);
                    commit('sethasConnected', true);
                    resolve(connection);
                } catch (error) {
                    reject(error);
                    //setTimeout(()=>connect(),5000);//连接失败后自动重连
                }

                //连接断开后重新连接
                // state.connection.onclose(async ()=>{
                //     await connect();
                // });
            });
        }
			
		   
    }
}